#include "adduserdialog.h"
#include "ui_adduserdialog.h"
#include <QMessageBox>

AddUserDialog::AddUserDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AddUserDialog)
{
    ui->setupUi(this);
}

AddUserDialog::~AddUserDialog()
{
    delete ui;
}

void AddUserDialog::on_cancelButton_clicked()
{
    this->close();
}

void AddUserDialog::on_addButton_clicked()
{
    if (ui->usernameEdit->text().size() > 3)
    {
        qDebug() << "sending new uer info to management";
        emit sendNewUserInfo(ui->usernameEdit->text(), ui->passwordEdit->text(), ui->adminCheckBox->isChecked()?1:0);
        qDebug() << "closeing addnewuser dialog";
        this->close();
    }
    else
    {
        QMessageBox::information(this, tr("Try again"), tr("username has to be 4-character long or longer"));
    }
}
